package com.lx.generator.aspect;

import com.lx.generator.monitor.TpsCounter;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * @author lX
 * @version JDK 8
 * @className TpsMonitoringAspect (此处以class为例)
 * @date 2024/11/10
 * @description TODO
 */
@Aspect
public class TpsMonitoringAspect {

    private TpsCounter tpsCounter;

    public TpsMonitoringAspect(TpsCounter tpsCounter) {
        this.tpsCounter = tpsCounter;
    }

    @Around("execution(* com.lx.idgenerator.segement.CacheSegmentIDGenerator.genId(..))")
    public Object monitorTps(ProceedingJoinPoint joinPoint) throws Throwable {
        tpsCounter.increment(); // 记录方法调用次数
        return joinPoint.proceed();
    }
}
